/**
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */

package org.geoscheduler.commons.marshaller.decls;

import org.geoscheduler.commons.marshaller.JSONFieldDecl;
import org.geoscheduler.commons.marshaller.JSONMarshaller;
import org.geoscheduler.commons.tools.PropertyDescriptor;

/**
 * 
 * <h2>JSONStringField</h2>
 * <p>
 * {@link String} property marshaller/unmarshaller.
 * </p>
 * 
 * @author lko
 */
public class JSONStringField extends JSONAbstractSimpleFieldDecl<String> {

	public JSONStringField(PropertyDescriptor<String> desc, String defValue) {
		super(desc, defValue);
	}

	public JSONStringField(PropertyDescriptor<String> desc) {
		super(desc);
	}

	public String decString(String value) {
		return value == null ? getDefaultValue() : value;
	}

	public String encString(String value) {
		return value;
	}

	public static class Factory extends BaseAbstractFactory<String> {

		public JSONFieldDecl<String> create(PropertyDescriptor<String> desc, JSONMarshaller marshaller) {
			return new JSONStringField(desc);
		}

		@Override
		public boolean isApplicable(PropertyDescriptor<?> desc) {
			return super.isApplicable(desc) && String.class.isAssignableFrom(desc.getType());
		}

	}
}
